#include "mainscene.h"
#include "ui_mainscene.h"

MainScene::MainScene(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //设置窗口
    //固定尺寸
    this->setFixedSize(mainSceneWidth,mainSceneHeight);
    //标题
    this->setWindowTitle(mainSceneName);
    //图标
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));

    //创建新手场景
    this->pScene = new PrimaryScene;
    //创建boss场景
    this->bScene = new Boss;
    //创建模仿场景
    this->iScene = new ImitateScene;
    //创建模仿场景
    this->rScene = new Record;

    //创建新手按钮
    PushButton_01 * start1 = new PushButton_01(":/res/xsms.png");
    start1->setParent(this);
    start1->move(this->width()*0.5-start1->width()*0.5,this->height()*0.7-150);
    connect(start1,&PushButton_01::clicked,[=](){
        start1->zoom1();
        start1->zoom2();
        //延时
        QTimer::singleShot(500,this,[=](){
            pScene->setGeometry(this->geometry());
            this->pScene->show();
            this->hide();
        });
    });

    //创建boss按钮
    PushButton_01 * start3 = new PushButton_01(":/res/bossboss.png");
    start3->setParent(this);
    start3->move(this->width()*0.5-start3->width()*0.5-250,this->height()*0.7);
    connect(start3,&PushButton_01::clicked,[=](){
        start3->zoom1();
        start3->zoom2();
        //延时
        QTimer::singleShot(500,this,[=](){
            bScene->setGeometry(this->geometry());
            this->bScene->show();
            this->hide();
            });
    });

    //创建模仿按钮
    PushButton_01 * start4 = new PushButton_01(":/res/mfms.png");
    start4->setParent(this);
    start4->move(this->width()*0.5-start4->width()*0.5+250,this->height()*0.7);
    connect(start4,&PushButton_01::clicked,[=](){
        start4->zoom1();
        start4->zoom2();
        //延时
        QTimer::singleShot(500,this,[=](){
            iScene->setGeometry(this->geometry());
            this->iScene->show();
            this->hide();
            });
    });

    //创建历史记录按钮
    PushButton_01 * start5 = new PushButton_01(":/res/yxjj.png");
    start5->setParent(this);
    start5->move(this->width()*0.5-start5->width()*0.5,this->height()*0.7-300);
    connect(start5,&PushButton_01::clicked,[=](){
        start5->zoom1();
        start5->zoom2();
        //延时
        QTimer::singleShot(500,this,[=](){
            rScene->setGeometry(this->geometry());
            this->rScene->show();
            this->hide();
            });
    });


    //监听新手关卡场景
    connect(this->pScene,&PrimaryScene::PrimarySceneBack,[=](){
        this->setGeometry(pScene->geometry());
        this->show();
        this->pScene->hide();
    });

    //监听boss关卡场景
    connect(this->bScene,&Boss::BossSceneBack,[=](){
        this->setGeometry(bScene->geometry());
        this->show();
        this->bScene->hide();
    });

    //监听模仿关卡场景
    connect(this->iScene,&ImitateScene::ImitatecSceneBack,[=](){
        this->setGeometry(iScene->geometry());
        this->show();
        this->iScene->hide();
    });

    //监听record关卡场景
    connect(this->rScene,&Record::RecordSceneBack,[=](){
        this->setGeometry(rScene->geometry());
        this->show();
        this->rScene->hide();
    });
}


MainScene::~MainScene()
{
    delete ui;
}

void MainScene::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/bfda0be809541c57e1407952d1e6042.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //标题
    pix.load(":/res/Title.png");
    painter.drawPixmap((this->width()-pix.width())*0.5,30,pix);
}
